{extend name="common/common" /}

{block name="style"}
<style media="screen">
	#cusTable{
		min-width: 1200px;
	}
	#tool_bar{
		position: absolute;
	}
	#stuTable{
		display: none;
	}
	#markShade{
		position: fixed;
		z-index: 9999999999999;
		background-color: #000;
		opacity: 0.3;
		display: none;
		width: 100%;
		height: 100%;
	}
	#markShade h1 {
		color: #FFF;
		text-align: center;
		margin-top:300px;
	}
</style>
{/block}

{block name="content"}
<div id="markShade">
	<h1>正在导出</h1>
</div>
<div class="wrapper wrapper-content animated fadeInRight">
	<div class="ibox float-e-margins">
		<div class="ibox-title">
			<h5>人数金额统计</h5>
		</div>
		<div class="ibox-content">
			<div id="tool_bar">
				<form class="layui-form" action="" id="seaForm">
					<div class="layui-form-item">
						<label class="layui-form-label">年份</label>
						<div class="layui-input-inline" style="width:100px;">
							<input type="text" name="seaTime" class="layui-input" id="seaTime" readonly>
						</div>
						<button type="button" id="search" class="btn btn-info" style="margin-top: 2px;">
							查询
						</button>
					</div>
				</form>
			</div>

			<div id="seaBatchBox" style="display:none;">
				<form class="layui-form" action="" id="seaForm">
					<input type="hidden" id="st_url" value="">
					<label class="layui-form-label">批次</label>
					<div class="layui-input-inline" style="width:100px;">
						<input type="text" name="seaBatch" class="layui-input" id="seaBatch">
					</div>
					<button type="button" id="seaBatchBtn" class="btn btn-info" style="margin-top: 2px;">
						查询
					</button>
				</form>
			</div>

			<table id="cusTable">
				<thead>
					<tr>
						<th data-width="100px" data-field="name">名称</th>
						<th data-width="50px" data-field="num_ing">在读人数</th>
						<th data-width="50px" data-field="num_end">毕业人数</th>
						<th data-width="50px" data-field="num_stop">休学人数</th>
						<th data-width="50px" data-field="num_out">退学人数</th>
						<th data-width="50px" data-field="num_total">总人数</th>
						<th data-width="50px" data-field="tuition">学费</th>
						<th data-width="50px" data-field="registration">报名费</th>
						<th data-width="50px" data-field="material_cost">资料费</th>
						<th data-width="80px" data-field="photo_collection">照片采集费</th>
						<th data-width="50px" data-field="money_total">总金额</th>
					</tr>
				</thead>
			</table>
			<table id="stuTable">
				<thead>
					<tr>
						<th data-width="100px" data-field="name">姓名</th>
						<th data-width="100px" data-field="batch">批次</th>
						<th data-width="50px" data-field="tuition">学费</th>
						<th data-width="50px" data-field="registration">报名费</th>
						<th data-width="50px" data-field="material_cost">资料费</th>
						<th data-width="80px" data-field="photo_collection">照片采集费</th>
						<th data-width="50px" data-field="money_total">总金额</th>
					</tr>
				</thead>
			</table>
		</div>
	</div>
</div>
{/block}

{block name="script"}
<script type="text/javascript" src="__JS__/tableExport.js"></script>
<script type="text/javascript" src="__JS__/bootstrap-table-export.js"></script>
<script type="text/javascript">
layui.use('laydate', function(){
	var laydate = layui.laydate;
		laydate.render({
		elem: '#seaTime',
		type: "year"
	});
});


$(function(){
	$("#seaTime").val(new Date().getFullYear());
	var url = "./num_price_statistics";
	initTable(url);

	$("#search").on("click",function(){
		var url = "./num_price_statistics";
		initTable(url);
	});
	$("#seaBatchBtn").on("click",function(){
		var url = $("#st_url").val();
		initTableSt(url);
	})
})

function initTable(url) {
	//先销毁表格
	$('#cusTable').bootstrapTable('destroy');
	//初始化表格,动态从服务器加载数据
	$("#cusTable").bootstrapTable({
		method: "post", //使用get请求到服务器获取数据
		url: url, //获取数据的地址
		sidePagination: "server", //表示服务端请求
		striped: true, //表格显示条纹
		pagination: true, //启动分页
		pageSize: 100, //每页显示的记录数
		pageNumber: 1, //当前第几页
		pageList: [100,200,300,400,500], //记录数可选列表
		paginationFirstText: "首页",
		paginationPreText: "上一页",
		paginationNextText: "下一页",
		paginationLastText: "尾页",
		queryParamsType: "--",
		resizable:true,//可伸缩
		showColumns:true,
		showExport: true,  //是否显示导出按钮
		exportTypes:['excel'],  //导出文件类型
		Icons:'glyphicon-export',
		exportOptions:{
			// ignoreColumn: [0,1],  //忽略某一列的索引
			fileName: '财务人数统计表格',  //文件名称设置
			worksheetName: '财务人数统计表格',  //表格工作区名称
			tableName: '财务人数统计表格',
			excelstyles: ['background-color', 'color', 'font-size', 'font-weight'],
			onMsoNumberFormat:function (cell, row, col) {
			   var result = "";
			   if (row > 0 && col == 0)
				   result = "\\@";
			   return result;
		   }
		},
		queryParams: function queryParams(params) { //设置查询参数
			var param = {
				pageNumber: params.pageNumber,
				pageSize: params.pageSize,
				seaTime:$("#seaTime").val()
			};
			return param;
		},
		onLoadSuccess: function(res) { //加载成功时执行
			if (111 == res.code) {
				window.location.reload();
			}
			layer.msg("加载成功", {time: 1000});
			var tr = '<tr><td class="text-right span-strong">总计</td>'
				   + '<td class="span-strong">' + res.sum0 + '</td>'
				   + '<td class="span-strong">' + res.sum1 + '</td>'
				   + '<td class="span-strong">' + res.sum2 + '</td>'
				   + '<td class="span-strong">' + res.sum3 + '</td>'
				   + '<td class="span-strong">' + res.sum4 + '</td>'
				   + '<td class="span-strong">' + res.sum5 + '</td>'
				   + '<td class="span-strong">' + res.sum6 + '</td>'
				   + '<td class="span-strong">' + res.sum7 + '</td>'
				   + '<td class="span-strong">' + res.sum8 + '</td>'
				   + '<td class="span-strong">' + res.sum9 + '</td></tr>';
			$("#cusTable tbody").append(tr);


			$(".export>.dropdown-menu>li:nth-child(1)>a").html('导出');
			$(".getTable").on("click",function(){
				$('#tool_bar').hide();
				var url = $(this).attr("data-url");
				initTable(url);
			});

			$(".getST").on("click",function(){
				var url = $(this).attr("data-url");
				initTableSt(url);
			});
		},
		onLoadError: function() { //加载失败时执行
			layer.msg("加载数据失败");
		},
		onDblClickRow: function(row) {
			console.log(row);
		}
	});
}

function initTableSt(url){
	$("#st_url").val(url);
	$('#cusTable').bootstrapTable('destroy');
	$("#cusTable").hide();
	$("#stuTable").show();
	$("#seaBatchBox").show();
	$('#stuTable').bootstrapTable('destroy');
	$("#stuTable").bootstrapTable({
		method: "post", //使用get请求到服务器获取数据
		url: url, //获取数据的地址
		sidePagination: "server", //表示服务端请求
		striped: true, //表格显示条纹
		pagination: true, //启动分页
		pageSize: 100, //每页显示的记录数
		pageNumber: 1, //当前第几页
		pageList: [100,200,300,400,500], //记录数可选列表
		paginationFirstText: "首页",
		paginationPreText: "上一页",
		paginationNextText: "下一页",
		paginationLastText: "尾页",
		queryParamsType: "--",
		resizable:true,//可伸缩
		showColumns:true,
		showExport: true,  //是否显示导出按钮
		exportTypes:['excel'],  //导出文件类型
		Icons:'glyphicon-export',
		exportOptions:{
			// ignoreColumn: [0,1],  //忽略某一列的索引
			fileName: '财务人数统计表格',  //文件名称设置
			worksheetName: '财务人数统计表格',  //表格工作区名称
			tableName: '财务人数统计表格',
			excelstyles: ['background-color', 'color', 'font-size', 'font-weight'],
			onMsoNumberFormat:function (cell, row, col) {
			   var result = "";
			   if (row > 0 && col == 0)
				   result = "\\@";
			   return result;
		   }
		},
		queryParams: function queryParams(params) { //设置查询参数
			var param = {
				pageNumber: params.pageNumber,
				pageSize: params.pageSize,
				seaTime:$("#seaTime").val(),
				seaBatch:$("#seaBatch").val()
			};
			return param;
		},
		onLoadSuccess: function(res) { //加载成功时执行
			if (111 == res.code) {
				window.location.reload();
			}
			layer.msg("加载成功", {time: 1000});
			var li = "<li data-type='all' data_url='"+url+"' id='ExportAll'><a href='javascript:void(0)'>导出全部</a></li>";
			$(".export>.dropdown-menu").append(li);
			$(".export>.dropdown-menu>li:nth-child(1)>a").html('导出当前');
			$(".getTable").on("click",function(){
				$('#tool_bar').hide();
				var url = $(this).attr("data-url");
				initTable(url);
			});

			$(".getST").on("click",function(){
				var url = $(this).attr("data-url");
				initTableSt(url);
			});

			$("#ExportAll").on('click',function(){
				var where = $(this).attr("data_url").split("?")[1];
				where += "&seaTime="+$("#seaTime").val();
				var ExUrl = "./NumMoneyStatisticsExportAll?" + where;
				$.post(ExUrl,function(){
					$('#markShade').show();
					setTimeout(function(){
						window.open("/upload/excel/download_finance_num" + {:session("id")} + ".xls");
						$('#markShade').hide();
					},5000);
				});
			});
		},
		onLoadError: function() { //加载失败时执行
			layer.msg("加载数据失败");
		},
		onDblClickRow: function(row) {
			console.log(row);
		}
	});
}
</script>
{/block}
